﻿using System;
using System.Collections;

namespace SuperCaptcha.Mvc.Processor
{
    internal sealed class LibraryHelper
    {
        internal static string GenerateRandomCode(int codeLength = 6)
        {
            codeLength = (codeLength <= 0) ? 6 : codeLength;
            ArrayList charPool = new ArrayList();
            Random randomObj = new Random();
            
            for (char i = 'A'; i <= 'Z'; i++) charPool.Add(i);
            for (char i = 'a'; i <= 'z'; i++) charPool.Add(i);
            for (char i = '0'; i <= '9'; i++) charPool.Add(i);

            string generatedString = string.Empty;
            for (var i = 0; i < codeLength; i++)
                generatedString += charPool[randomObj.Next(charPool.Count)].ToString();
            return generatedString;
        }
    }
}
